package vip.web3.admin.sys.service.impl.biz;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import vip.web3.admin.common.utils.Query;
import vip.web3.admin.sys.dao.biz.AProductDao;
import vip.web3.admin.sys.entity.biz.AProductEntity;
import vip.web3.admin.sys.entity.biz.AUserEntity;
import vip.web3.admin.sys.form.user.ProductPageForm;
import vip.web3.admin.sys.service.biz.IAProductService;
import vip.web3.common.utils.Convert;
import vip.web3.common.utils.PageUtils;

import java.util.Map;
import java.util.Objects;

/**
 * 轮次购买规则Service业务层处理
 *
 * aut-horlilei
 * @date 2024-09-27
 */
@Service
public class AProductServiceImpl extends ServiceImpl<AProductDao, AProductEntity> implements IAProductService {


    /**
     * 批量删除轮次购买规则
     *
     * @param ids 需要删除的轮次购买规则主键
     * @return 结果
     */
    @Override
    public int deleteAProductByIds(String ids) {
        return this.baseMapper.deleteAProductByIds(Convert.toIntArray(ids));
    }

    @SuppressWarnings("all")
    @Override
    public PageUtils pageProducts(Map<String, Object> params, ProductPageForm form) {

        IPage<AUserEntity> page = this.page(
                new Query<AProductEntity>().getPage(params),
                this.lambdaQuery()
                        .eq(Objects.nonNull(form.getStatus()), AProductEntity::getStatus, form.getStatus())
                        .like(StringUtils.isNotBlank(form.getKeyWord()), AProductEntity::getTitle, form.getKeyWord())
                        .getWrapper()
        );

        return new PageUtils(page);
    }

}
